package com.jraft;

import com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore;
import com.alipay.sofa.jraft.rhea.client.RheaKVStore;
import com.alipay.sofa.jraft.rhea.options.PlacementDriverOptions;
import com.alipay.sofa.jraft.rhea.options.RegionRouteTableOptions;
import com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions;
import com.alipay.sofa.jraft.rhea.options.configured.MultiRegionRouteTableOptionsConfigured;
import com.alipay.sofa.jraft.rhea.options.configured.PlacementDriverOptionsConfigured;
import com.alipay.sofa.jraft.rhea.options.configured.RheaKVStoreOptionsConfigured;

import java.util.List;

public class Client2 {


    public static void main(String[] args) {
        String serverList="127.0.0.1:8891,127.0.0.1:8892,127.0.0.1:8893" +
                ",127.0.0.1:8894,127.0.0.1:8895";

        RheaKVStore store=new DefaultRheaKVStore();

        List<RegionRouteTableOptions> routeTables= MultiRegionRouteTableOptionsConfigured
                .newConfigured()
                .withInitialServerList(-1L,serverList)
                .config();

        PlacementDriverOptions driverOptions= PlacementDriverOptionsConfigured
                .newConfigured()
                .withFake(true)
                .withRegionRouteTableOptionsList(routeTables)
                .config();

        RheaKVStoreOptions storeOptions= RheaKVStoreOptionsConfigured
                .newConfigured()
                .withInitialServerList(serverList)
                .withPlacementDriverOptions(driverOptions)
                .config();

        RheaKVStore kvStore=new DefaultRheaKVStore();

        kvStore.init(storeOptions);

        String key="join";
        String value="hello world";

        byte[] bytes = kvStore.bGet(key.getBytes());


        System.out.println("new String(bytes) = " + new String(bytes));


    }

}
